package com.water.camera.adapter;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.MoreItemBinding;
import com.water.camera.it.EditListener;

import java.util.List;

public class PinEditListAdapter extends EditListAdapter {
    public PinEditListAdapter(List<EditItem> list, EditListener listener) {
        super(list, listener);
    }

    @Override
    public int getItemViewType(int position) {
        if (position == getItemCount() - 1) {
            return 1;
        }
        return 0;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == 0) {
            return super.onCreateViewHolder(parent, viewType);
        } else {
            MoreItemBinding binding = MoreItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
            return new MoreHolder(binding);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MoreHolder) {
            ((MoreHolder) holder).bind();
        } else {
            super.onBindViewHolder(holder, position);
        }
    }

    class MoreHolder extends RecyclerView.ViewHolder {
        MoreItemBinding binding;

        MoreHolder(MoreItemBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }

        void bind() {
            itemView.setOnClickListener(v -> {
                listener.addWord();
            });
        }
    }
}
